﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web;
using System.Web.UI;
using System.Text.RegularExpressions;

/// <summary>
/// Summary description for GlobalVariables
/// </summary>
public static class GlobalVariables
{
    //private  hachiModel.hachiEntities _en = null;
    private static MembershipModel.MembershipEntities _men =null;
    private static string _ti = null;

    public static hachiModel.hachiEntities EN
    {
        get
        {
            return HttpContext.Current.Application["Bar"] as hachiModel.hachiEntities;
        }
        set
        {
            HttpContext.Current.Application["Bar"] = value;
        }
    }

    //public  hachiModel.hachiEntities hachiEntities
    //{
    //    get
    //    {
    //        if (_en==null)
    //            _en = new hachiModel.hachiEntities();
    //        return _en;
    //    }
    //}
    public static MembershipModel.MembershipEntities MembershipEntities
    {
        get
        {
            if (_men==null)
                _men = new MembershipModel.MembershipEntities();
            return _men;
        }
    }
    public static string ti
    {
        get
        {
            if (_ti == null)
                _ti = DateTime.Now.ToString();
            return _ti;
        }
    }

    public static int GlobalCounter { get; set; }

}
public static class hachiCookies
{
    public static string getCookieValue(string name)
    {
        HttpCookie cookie = HttpContext.Current.Request.Cookies["HachiPreferences"];
        return cookie == null ? null : cookie[name];
    }
    public static void setCookieValue(string name, string Value)
    {
        HttpCookie cookie = HttpContext.Current.Request.Cookies["HachiPreferences"];
        if (cookie == null)
        {
            cookie = new HttpCookie("HachiPreferences");
        }
        cookie[name] = Value;
        cookie.Expires = DateTime.Now.AddYears(1);
        HttpContext.Current.Response.Cookies.Add(cookie);
    }
}
public class StringUtil
{
    private static readonly string[] VietnameseSigns = new string[]{"aAeEoOuUiIdDyY","áàạảãâấầậẩẫăắằặẳẵ","ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ","éèẹẻẽêếềệểễ","ÉÈẸẺẼÊẾỀỆỂỄ","óòọỏõôốồộổỗơớờợởỡ","ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ","úùụủũưứừựửữ","ÚÙỤỦŨƯỨỪỰỬỮ","íìịỉĩ","ÍÌỊỈĨ","đ","Đ","ýỳỵỷỹ","ÝỲỴỶỸ"};

    public static string RemoveSign4VietnameseString(string str)
    {
        for (int i = 1; i < VietnameseSigns.Length; i++)
            for (int j = 0; j < VietnameseSigns[i].Length; j++)
                str = str.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
        return str;
    }
    
    public static string RemoveSpecialCharacters(string input)
    {
        Regex r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
        return r.Replace(input, String.Empty);
    }

    public static string RemoveVietSignAndSpecialChar(string input)
    {
        return RemoveSpecialCharacters(RemoveSign4VietnameseString(input));
    }
    public static string RemoveVietSignSpecialCharAndSpaceChar(string input)
    {
        return  RemoveSpecialCharacters(RemoveSign4VietnameseString(input)).Trim().Replace(" ","-").Replace("--","-");
    }
}
public class Item
{
    public int ItemID { get; set; }
    public int CateID { get; set; }
    public int PCateID { get; set; }
    public string ItemName { get; set; }
    public string ItemNote { get; set; }
    public int Quantity { get; set; }
}